﻿using System.Collections.Generic;

namespace DesignModeConsole.OOPAndPOP;

/*
 本文讲述那些因为滥用get、set所导致的像面向对象，但是实际上是面向过程的行为
 */

/// <summary>
/// 面向过程
/// </summary>
public class ShoppingCart1
{
    public int ItemCount { get; set; }

    public double ToTalPrice { get; set; }

    public List<ShoppingCartItem> Items { get; set; }
}

/// <summary>
/// 面向对象
/// </summary>
public class ShoppingCart2
{
    public int ItemCount { get; private set; }

    public double ToTalPrice { get; private set; }

    public List<ShoppingCartItem> Items { get; }

    public IReadOnlyCollection<ShoppingCartItem> GetItems()
    {
        return Items;
    }

    public void AddItem(ShoppingCartItem item)
    {
        Items.Add(item);
        ItemCount++;
        ToTalPrice += item.Price;
    }

    public void Clear()
    {
        Items.Clear();
        ToTalPrice = 0;
        ItemCount = 0;
    }
}

public class ShoppingCartItem
{
    public string ShopId { get; set; }

    public double Price { get; set; }
}